# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy

#要保存数据的话在这里建立对应的类
#要保存的数据都需要在对应的类中通过scrapy.Field()创建实例
#这里面是以类似字典形式储存
#用BaseItem继承scrapy.Item，后面的类再继承BaseItem，这样导出到sql就方便多了
class BaseItem(scrapy.Item):
    def to_sql(self):
        # sql = "insert into hero (id, name) values (%s, %s);
        sql = "insert into " + self.table_name + "(" + ",".join(self.keys()) + ") VALUES (" + ",".join(["%s"] * len(self.keys())) + ");"
        return sql

    def get_args(self):
        return tuple([self.get(key) for key in self.keys()])

class XpcItem(BaseItem):
    # define the fields for your item here like:
    # name = scrapy.Field()
    pass

class MovieItem(BaseItem):
    print('到item了：class MovieItem')
    table_name = 'movies'#后面向BaseItem传值
    movie_title = scrapy.Field()#field是字段的伊苏
    movie_desc = scrapy.Field()
    movie_id = scrapy.Field()
    movie_duration = scrapy.Field()
    movie_publish = scrapy.Field()
    movie_play = scrapy.Field()
    movie_like = scrapy.Field()
    image_url = scrapy.Field()

class DetailItem(BaseItem):
    table_name = 'detail'  # 后面向BaseItem传值
    transmit = scrapy.Field()
    movie_id = scrapy.Field()

class MovieImage(scrapy.Item):#图片就不存数据库了，直接继承item就好
    movie_id = scrapy.Field()
    image = scrapy.Field()


class MovieCommentItem(BaseItem):
    table_name = 'comment'
    movie_id = scrapy.Field()
    content = scrapy.Field()
    user_headurl = scrapy.Field()
    user_id = scrapy.Field()
    followee = scrapy.Field()
    follower = scrapy.Field()
    collected = scrapy.Field()
    user_like = scrapy.Field()

class MoviePlayUrlItem(BaseItem):
    table_name = 'playurl'
    movie_id = scrapy.Field()
    profile = scrapy.Field()
    url = scrapy.Field()

class UserHead(scrapy.Item):#图片就不存数据库了，直接继承item就好
    user_head = scrapy.Field()
    user_id = scrapy.Field()